package se.sll.service.catalogue.notif.smtp;

import org.apache.camel.builder.RouteBuilder;
import se.sll.service.catalogue.common.property.CatalogProperties;

/**
 *
 * @author Jiri Uosukainen
 */
public class LoadSmtpCamelRoute extends RouteBuilder {
    
    
    /**
     * 1. Listen to JMS-queue for outgoing notifications on expiring capacities
     * 2. Transform QUEUE message to fit smtp
     * 3. Send 
     * @throws Exception 
     */
    @Override
    public void configure() throws Exception {
        
        from("jms:queue:" + CatalogProperties.JMS_SMTP_QUEUE_JNDI + "?testConnectionOnStartup=true")
            .errorHandler(deadLetterChannel("jms:queue:" + CatalogProperties.JMS_DLQ_JNDI).maximumRedeliveries(Integer.parseInt(CatalogProperties.getProperty(CatalogProperties.NAME.NOTIFICATION_CAPACITY_MAX_REDELIVERIES))))
            .to("log:se.sll.service.catalogue.notif.smtp.LoadSmtpCamelRoute?showAll=true&multiline=true")
            .split().method(SmtpSplitProcessor.class, "splitMessage")
            .to("log:se.sll.service.catalogue.notif.smtp.LoadSmtpCamelRoute?showAll=true&multiline=true")
            .to("smtp://"+CatalogProperties.getProperty(CatalogProperties.NAME.SMTP_MAILSERVER_HOST)+":"+CatalogProperties.getProperty(CatalogProperties.NAME.SMTP_MAILSERVER_PORT));
    }
}
